Imports


In [1]:
%pylab inline

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

try:
    from future.builtins import (bytes, str, open, super, range,
                                 zip, round, input, int, pow, object)
except:
    pass

# ---- Standard Libraries not included in pylab
import collections
import glob
import json
import random
import time
from StringIO import StringIO

# ---- Extra Libraries for additional functionality
import elasticsearch
from elasticsearch import Elasticsearch
es = Elasticsearch(['http://search-01.ec2.internal:9200'])


Populating the interactive namespace from numpy and matplotlib

Look at the Current Mapping


In [2]:
mapping = es.indices.get_mapping("gsod")
obs_mapping = collections.OrderedDict(mapping['gsod']['mappings']['observation']['properties'])
for ob_params in obs_mapping:
    print("{:18s}{}".format(ob_params, obs_mapping[ob_params]))


Num of Obs        {u'type': u'string'}
Wind Speed        {u'type': u'string'}
FRSHTT            {u'type': u'string'}
Snow Depth        {u'type': u'string'}
Gust              {u'type': u'string'}
SLP               {u'type': u'string'}
Mean Temp         {u'type': u'string'}
Max Wind Speed    {u'type': u'string'}
Max Temp          {u'type': u'string'}
STP               {u'type': u'string'}
Min Temp          {u'type': u'string'}
WBAN              {u'type': u'string'}
Date              {u'type': u'date', u'format': u'dateOptionalTime'}
Station Id        {u'type': u'string'}
Dew Point         {u'type': u'string'}
Precipitation     {u'type': u'string'}
Visibility        {u'type': u'string'}

In [3]:
%%bash
curl -XPUT 'http://search-01.ec2.internal:9200/gsod_test'
curl -XPUT 'http://search-01.ec2.internal:9200/gsod_test/_mapping/observation' -d '
{
    "observation": {
        "properties": {
            "Num of Obs": {"type": "integer"},
            "Wind Speed": {"type": "float"},
            "FRSHTT": {"type": "string"},
            "Snow Depth": {"type": "float"},
            "Gust": {"type": "float"},
            "SLP": {"type": "float"},
            "Mean Temp": {"type": "float"},
            "Max Wind Speed": {"type": "float"},
            "Max Temp": {"type": "float"},
            "STP": {"type": "float"},
            "Min Temp": {"type": "float"},
            "WBAN": {"type": "string"},
            "Date": {"type": "date", "format": "dateOptionalTime"},
            "Station Id": {"type": "string"},
            "Dew Point": {"type": "float"},
            "Precipitation": {"type": "float"},
            "Visibility": {"type": "float"}
        }
    }
}'


{"error":"RemoteTransportException[[search-06][inet[/172.31.49.239:9300]][indices:admin/create]]; nested: IndexAlreadyExistsException[[gsod_test] already exists]; ","status":400}{"acknowledged":true}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   178  100   178    0     0  19324      0 --:--:-- --:--:-- --:--:-- 25428
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   849  100    21  100   828   2095  82618 --:--:-- --:--:-- --:--:--  101k

In [4]:
mapping = es.indices.get_mapping("gsod_test")
obs_mapping = collections.OrderedDict(mapping['gsod_test']['mappings']['observation']['properties'])
for ob_params in obs_mapping:
    print("{:18s}{}".format(ob_params, obs_mapping[ob_params]))


Num of Obs        {u'type': u'integer'}
Wind Speed        {u'type': u'float'}
FRSHTT            {u'type': u'string'}
Snow Depth        {u'type': u'float'}
Gust              {u'type': u'float'}
SLP               {u'type': u'float'}
Mean Temp         {u'type': u'float'}
Max Wind Speed    {u'type': u'float'}
Max Temp          {u'type': u'float'}
STP               {u'type': u'float'}
Min Temp          {u'type': u'float'}
WBAN              {u'type': u'string'}
Date              {u'type': u'date', u'format': u'dateOptionalTime'}
Station Id        {u'type': u'string'}
Dew Point         {u'type': u'float'}
Precipitation     {u'type': u'float'}
Visibility        {u'type': u'float'}

In [6]:
%%bash

curl -XDELETE 'http://search-01.ec2.internal:9200/gsod_test'


{"error":"IndexMissingException[[gsod_test] missing]","status":404}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    67  100    67    0     0  15120      0 --:--:-- --:--:-- --:--:-- 22333

In [ ]:
%%bash

curl -XPUT 'http://search-01.ec2.internal:9200/gsod_test'
curl -XPUT 'http://search-01.ec2.internal:9200/gsod_test/_mapping/observation' -d '
{
    "observation": {
        "properties": {
            "Num of Obs": {"type": "integer"},
            "Wind Speed": {"type": "float"},
            "FRSHTT": {"type": "string"},
            "Snow Depth": {"type": "float"},
            "Gust": {"type": "float"},
            "SLP": {"type": "float"},
            "Mean Temp": {"type": "float"},
            "Max Wind Speed": {"type": "float"},
            "Max Temp": {"type": "float"},
            "STP": {"type": "float"},
            "Min Temp": {"type": "float"},
            "WBAN": {"type": "string"},
            "Date": {"type": "date", "format": "dateOptionalTime"},
            "Station Id": {"type": "string"},
            "Dew Point": {"type": "float"},
            "Precipitation": {"type": "float"},
            "Visibility": {"type": "float"}
        }
    }
}'